import { _decorator, Component, Label } from 'cc';
import { Ab_DataTransfer_bA } from '../../../A-FRAME/A-LIB/lib.b.data';
import Ab_GlobalDC_bA from '../../../A-FRAME/common/data.global.center';
import Ab_Config_bA from '../../manager/config.manager';
import Ab_GameDC_bA from '../../manager/data.game.center';
import Ab_GameAssets_bA from '../../manager/game.assets';
const { ccclass, property } = _decorator;

@ccclass('Ab_Statistics_bA')
export class Ab_Statistics_bA extends Component {

	protected onLoad(): void {
		this.Ab_renderLocalUI_bA();
		this.Ab_listening_bA();
	}

	private Ab_listening_bA(){
		let [lbl_pass, lbl_challenge, lbl_average] = ['round', 'challenge', 'symbol'].map(name=>this.node.getChildByName('lbl-value-'+name).getComponent(Label));
		let lbl_title = this.node.getChildByName('lbl-title').getComponent(Label);

		let date = new Date();
		let day_str = '';
		Ab_DataTransfer_bA.Ab_follow_bA(Ab_GameDC_bA.Ab_Status_bA, 'Ab_statistics_count_bA', (o, v)=>lbl_pass.string = String(v));
		Ab_DataTransfer_bA.Ab_follow_bA(Ab_GameDC_bA.Ab_Status_bA, 'Ab_statistics_round_bA', (o, v)=>lbl_challenge.string = String(v));
		Ab_DataTransfer_bA.Ab_follow_bA(Ab_GameDC_bA.Ab_Status_bA, 'Ab_statistics_free_bA', (o, v)=>lbl_average.string = Ab_Config_bA.Ab_symbolString_bA(v));
		Ab_DataTransfer_bA.Ab_follow_bA(Ab_GlobalDC_bA.Ab_Clock_bA, 'Ab_current_time_bA', (o, v)=>{
			date.setTime(v);
			let dstr = [date.getFullYear(), date.getMonth()+1, date.getDate()].map(v=>v.toString().padStart(2, '0')).join('.');
			if(day_str == dstr) return void 0;

			day_str = dstr;
			lbl_title.string = Ab_GameAssets_bA.Ab_getLangText_bA(6, dstr);
		});
	}

	private Ab_renderLocalUI_bA(){
		(<const>[
			['round', 7],
			['challenge', 8],
			['symbol', 9]
		]).forEach(([name, idx])=>this.node.getChildByName('lbl-head-'+name).getComponent(Label).string = Ab_GameAssets_bA.Ab_getLangText_bA(idx));
	}
}

